﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PurchasedReceivedDetail.aspx.cs" Culture="en-GB" Inherits="Main_Inventory_PurchasedReceivedDetail" EnableEventValidation="false" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Purchased Received</title>
     <link href="../../Styles/accounts.css" rel="Stylesheet" type="text/css" />
     <script src="../../Menu/js/jquery.min.js" type="text/javascript"></script>
   <script language="javascript" type="text/javascript">
     function isNumberKey(control_id, evt)
      {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode > 47))
                    return false;

                if (charCode == 46)
                 {
                    var dotcount = document.getElementById(control_id).value.split('.').length - 1;
                    if (dotcount >= 1) 
                    {
                        return false;
                    }
                 }

                return true;
      }
            </script>
            
            

<script type="text/javascript" language="javascript">
        function isNumberKey(control_id, evt)
        {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode > 47))
            return false;

            if (charCode == 46)
            {
            var dotcount = document.getElementById(control_id).value.split('.').length - 1;
            if (dotcount >= 1)
            {
            return false;
            }
            }
            return true;
        }
        
         function calcQty()
         {
            var Count=document.getElementById("hidControl").value;
            var total_qty=0;
            for(var i=1;i<=Count;i++)
            {
              var qty=0;
              
              if(document.getElementById("txtQty"+i).value!='')
              {
                qty=parseFloat(document.getElementById("txtQty"+i).value);
                document.getElementById("txtQty"+i).value=qty.toFixed(2);                
              }
              total_qty+=qty;
            }
           document.getElementById("txtTotalItem").value=total_qty.toFixed(2);
         }
         
         
         function calcAmt()
         {
            var Count=document.getElementById("hidControl").value;
            var taxable_amt=0; 
            var VATCST_amt=0;
            var pretax_amt=0;
            for(var i=1;i<=Count;i++)
            {
              var qty=0;
              var amt=0;
              var total_amt=0;            
               
              if(document.getElementById("txtQty"+i).value!='')
              {
                var tax=document.getElementById("hidTaxRate"+i).value;
                qty=parseFloat(document.getElementById("txtQty"+i).value);
                if(document.getElementById("txtRateIncTax"+i).value!='')
                {
                    amt=parseFloat(document.getElementById("txtRateIncTax"+i).value);
                    document.getElementById("txtRateIncTax"+i).value=amt.toFixed(2);
                    
                    if(tax=='' || tax=='0')
                    {
                        total_amt=qty*amt;
                        document.getElementById("txtRateExcTax"+i).value=amt.toFixed(2);
                        taxable_amt += total_amt;
                    }
                    else
                    {
                        var  val = 1 + ((parseFloat(tax) * 100) / 1000) / 10;
                        rateExcl_amt=parseFloat(amt)/parseFloat(val);                      
                        document.getElementById("txtRateExcTax"+i).value=rateExcl_amt.toFixed(2);
                        total_amt=qty*amt;
                        taxable_amt += qty*rateExcl_amt;
                        VATCST_amt +=(qty*rateExcl_amt*tax)/100;
                    }
                    pretax_amt +=amt;
                }               
                else 
                {
                    document.getElementById("txtRateExcTax"+i).value='';
                }                            
                document.getElementById("txtAmountPayable"+i).value=total_amt.toFixed(2); 
              }                           
            }
           document.getElementById("txtTaxableAmt").value=taxable_amt.toFixed(2);
           document.getElementById("txtPreTotalTax").value=pretax_amt.toFixed(2);
           document.getElementById("txtVat").value=VATCST_amt.toFixed(2);
           var posttax_amt=taxable_amt+VATCST_amt;
           document.getElementById("txtPostTaxTotal").value=posttax_amt.toFixed(2);
           document.getElementById("txtGrandTotal").value=posttax_amt.toFixed(2);       
        }
           
         
         
         function CreditDays()
         {
            if( document.getElementById("txtCreditDay").value!='')
            {
                var days=document.getElementById("txtCreditDay").value;
                if(parseFloat(days)>365)
                {
                  alert('Maximum Credit Days is 365 days');
                  document.getElementById("txtCreditDay").value='365';
                }  
                 document.getElementById("radioCash").checked=false;
                 document.getElementById("radioCredit").checked=true;
            }
            else
            {
            document.getElementById("radioCash").checked=true;
            document.getElementById("radioCredit").checked=false;
            }        
         }

         
         function RoundOff()
         {
            var posttax=document.getElementById("txtPostTaxTotal").value;  
            if(document.getElementById("txtRoundoff").value!='')
            {   var roundoff=document.getElementById("txtRoundoff").value;
                var GrandTotal=parseFloat(posttax)+parseFloat(roundoff);
                document.getElementById("txtGrandTotal").value=GrandTotal.toFixed(2);
            }
            else
            {
               document.getElementById("txtRoundoff").value='0.00'
               document.getElementById("txtGrandTotal").value=parseFloat(posttax).toFixed(2);
            }
         }
         
         function ValidateItems()
         { 
            var flag=new Boolean(true);
            if(document.getElementById("ddlFormat").selectedIndex=='0')
            {
                alert('Please Select Bill Format ');
                document.getElementById("ddlFormat").focus();
                flag=false;
            } 
            else if(document.getElementById("ddlSupplier").selectedIndex=='0')
            {
                alert('Please Select Supplier ');
                document.getElementById("ddlSupplier").focus();
                flag=false;;
            } 
            else if(document.getElementById("txtVoucher").value=='' || document.getElementById("txtVoucher").value=='Number')
            {
                alert('Please Specify Voucher Number');
                document.getElementById("txtVoucher").focus();
                flag=false;
            }
            else  if(document.getElementById("ddlTaxGroup").selectedIndex=='0')
            {
                alert('Please Select Tax Group ');
                document.getElementById("ddlTaxGroup").focus();
                flag=false;
            } 
            else if(document.getElementById("txtDate").value=='' || document.getElementById("txtDate").value=='__/__/____')
            {
                alert('Please Specify P.O. Date');
                document.getElementById("txtDate").focus();
                flag=false;
            }            
            else if(document.getElementById("ddlItem1").selectedIndex=='0')
            {
                alert('Please Select At Least One Item ');
                document.getElementById("ddlItem1").focus();
                flag=false;
            } 
            else if(document.getElementById("txtQty1").value=='')
            {
                alert('Please Specify Quantity For First Item');
                document.getElementById("txtQty1").focus();
                flag=false;
            }
            else if(document.getElementById("txtRateIncTax1").value=='')
            {
                alert('Please Specify Rate Inclusive Tax');
                document.getElementById("txtRateIncTax1").focus();
                flag=false;
            }
            else 
            {
                flag=true;
            }
            return flag;
         }
         function ValidateItems1()
         { 
            var flag=new Boolean(true);
            var Count=document.getElementById("hidControl").value;
            for(var i=2;i<=Count;i++)
            {
                if(document.getElementById("ddlItem"+i).selectedIndex!='0')
                {
                    if(document.getElementById("txtQty"+i).value=='')
                    {
                        alert('Please Specify Quantity at Row No '+' '+i);
                        document.getElementById("txtQty"+i).focus();
                        flag=false;
                    }
                    if(document.getElementById("txtRateIncTax"+i).value=='')
                    {
                        alert('Please Specify Rate Inclusive Tax at Row No '+' '+i);
                        document.getElementById("txtRateIncTax"+i).focus();
                        flag=false;
                    }                    
                }
                else if(document.getElementById("txtQty"+i).value!='')
                {
                    if(document.getElementById("ddlItem"+i).selectedIndex=='0')
                    {
                        alert('Please Specify Item in Row No '+' '+i);
                        document.getElementById("ddlItem"+i).focus();
                        flag=false;
                    }
                    if(document.getElementById("txtRateIncTax"+i).value=='')
                    {
                        alert('Please Specify Rate Inclusive Tax at Row No '+' '+i);
                        document.getElementById("txtRateIncTax"+i).focus();
                        flag=false;
                    }                    
                }
                else if(document.getElementById("txtRateIncTax"+i).value!='')
                {
                    if(document.getElementById("txtQty"+i).value=='')
                    {
                        alert('Please Specify Quantity in Row No '+' '+i);
                        document.getElementById("txtQty"+i).focus();
                        flag=false;
                    }
                    if(document.getElementById("ddlItem"+i).selectedIndex=='0')
                    {
                        alert('Please Specify Item in Row No '+' '+i);
                        document.getElementById("ddlItem"+i).focus();
                        flag=false;
                    }                  
                }
            }
            return flag;
         }
        
        function ValidationInput()
        {
          if(ValidateItems()==true && ValidateItems1()==true)
          {
            return true;
          }
          else
          {
            return false;
          }
        }
    </script>

<style type="text/css">   
   #wrapper {
    width:90%;
    margin-left:5%;
    margin-right:5%;
    margin-top:5px;
}
ul.tabs {
    width:99%;
    margin:0;
    padding:0;
}
ul.tabs li {
    display:block;
    float:left;
    padding:0 5px;
}
ul.tabs li a {
    display:block;
    float:left;
    padding:5px;
    font-size:0.8em;
    background-color:#e0e0e0;
    color:#666;
    text-decoration:none;
}
.selected {
    font-weight:bold;
}
.tab-content {
	clear:both;
    border:1px solid #ddd;
    padding:1px;
}
</style>

<script type="text/javascript">

    $(document).ready(function() {

        $('.tabs a').click(function() {
            switch_tabs($(this));
        });

        switch_tabs($('.defaulttab'));

    });

    function switch_tabs(obj) {
        $('.tab-content').hide();
        $('.tabs a').removeClass("selected");
        var id = obj.attr("rel");

        $('#' + id).show();
        obj.addClass("selected");
    }

</script>            
</head>

<body>
    <form id="form1" runat="server">
     <div class="divmain">
         <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></asp:ScriptManager>        
        <acc:heading ID="pagehead" runat="server" HeadingText="Purchased Received" />
    </div>
     <asp:UpdateProgress DynamicLayout="false" ID="UpdProgress" runat="server">
            <ProgressTemplate>
                <div align="center"><img src="../../Images/ajax-loader.gif" /></div>
            </ProgressTemplate>
     </asp:UpdateProgress> 
    
    <div>
    
       <asp:UpdatePanel ID="UpdatePanel4" runat="server">
       
            <ContentTemplate>
             <div style="text-align:center; height:20px; width:50%; margin-left:22%; margin-right:25%"><asp:Label ID="lblMsg" runat="server" Font-Bold="true"></asp:Label></div> 
                 <table  class="tablecontentnoborder" style ="width:90%; margin-left:5%; margin-right:5%; padding: 0px; border:1px solid #818181;">
                <tr>
                    <td class="headtd" colspan="4">Purchase Received Details</td>
                </tr>
                
              
                
                <tr>
                    <td style="width:20%">Purchase Order Number</td>
                    <td style="width:20%; margin-left:8px;"> <asp:Label ID="LblPurchaseNumber" Font-Bold="true" runat="server"></asp:Label></td>
                    <td style="width:20%"> Supplier Name</td>
                    <td style="width:20%; margin-left:8px;"> <asp:Label ID="LblSupplierName" Font-Bold="true" runat="server"></asp:Label> </td>
                </tr>
                
                <tr>
                    <td style="width:20%"> Invoice No.<span style="color:Red">*</span></td>
                    <td style="width:20%"> <asp:TextBox ID="TxtInvoiceNo" onKeyPress="return isNumberKey(this.id,event)" CssClass="input" runat="server"> </asp:TextBox> 
                        <asp:RequiredFieldValidator ID="RFVInvoiceNo" runat="server" ControlToValidate="TxtInvoiceNo" ErrorMessage="*"></asp:RequiredFieldValidator>
                    </td>
                    
                    <td style="width:20%"> Invoice Date<span style="color:Red">*</span></td>
                    <td style="width:20%"> <asp:TextBox ID="TxtInvoiceDate" Width="75%" CssClass="input" runat="server"> </asp:TextBox>
                      <asp:ImageButton ID="btnDate" runat="server" ImageUrl="~/Images/calendar.gif" />
                      <asp:RequiredFieldValidator ID="RFVInvoiceDATE" runat="server" ControlToValidate="TxtInvoiceDate" ErrorMessage="*"></asp:RequiredFieldValidator>
                      <ajaxToolkit:CalendarExtender ID="cal" runat="server" PopupButtonID="btnDate" TargetControlID="TxtInvoiceDate" Format="dd/MM/yyyy"></ajaxToolkit:CalendarExtender>
                      <ajaxToolkit:MaskedEditExtender ID="maskExt" runat="server" MaskType="Date" Mask="99/99/9999" TargetControlID="TxtInvoiceDate" CultureName="pt-BR"></ajaxToolkit:MaskedEditExtender>
                      <ajaxToolkit:MaskedEditValidator ID="maskValid" runat="server" ControlExtender="maskExt" InvalidValueMessage="Invalid Date" IsValidEmpty="true" Display="Dynamic" ValidationGroup="V" ControlToValidate="TxtInvoiceDate"></ajaxToolkit:MaskedEditValidator>
                    </td>
                </tr>
                
                <tr>
                     <td style="width:20%"> MRR No.</td>
                    <td style="width:20%"><asp:TextBox ID="TxtMRR" onKeyPress="return isNumberKey(this.id,event)" CssClass="input" runat="server"> </asp:TextBox> </td>
                    <td style="width:20%"> Receive Date<span style="color:Red">*</span></td>
                    <td style="width:20%"> <asp:TextBox ID="TxtReceive" Width="75%" CssClass="input"  runat="server"> </asp:TextBox>
                      <asp:ImageButton ID="ImageDate" runat="server" ImageUrl="~/Images/calendar.gif" />
                      <ajaxToolkit:CalendarExtender ID="cal1" runat="server" PopupButtonID="ImageDate" TargetControlID="TxtReceive" Format="dd/MM/yyyy"></ajaxToolkit:CalendarExtender>
                      <ajaxToolkit:MaskedEditExtender ID="maskExtReceive" runat="server" MaskType="Date" Mask="99/99/9999" TargetControlID="TxtReceive" CultureName="pt-BR"></ajaxToolkit:MaskedEditExtender>
                      <ajaxToolkit:MaskedEditValidator ID="maskValidReceive" runat="server" ControlExtender="maskExtReceive" InvalidValueMessage="Invalid Date" IsValidEmpty="true" Display="Dynamic" ValidationGroup="V" ControlToValidate="TxtReceive"></ajaxToolkit:MaskedEditValidator>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TxtReceive" ErrorMessage="*"></asp:RequiredFieldValidator>
                  </td>
                </tr>
                
                <tr>
                    <td style="width:20%"> Remarks</td>
                    <td style="width:20%"> <asp:TextBox ID="TextBox1" CssClass="input" runat="server"> </asp:TextBox> </td>
                    <td style="width:20%"> Gate No.</td>
                    <td style="width:20%"> <asp:TextBox ID="TxtGate" CssClass="input" runat="server" > </asp:TextBox></td>
                </tr>
                             
               
              </table>
              
      <div id="wrapper">    
        <ul class="tabs">
            <li><a href="javascript:void(0)" class="defaulttab" rel="tabGeneral">General</a></li>
            
           
        </ul>
         <div class="tab-content" id="tabGeneral" runat="server">
                <asp:HiddenField ID="HidGrdRowCount" runat="server" />
                <asp:HiddenField ID="HidGrdTotal" runat="server" />
                <asp:GridView ID="GridDisplay" runat="server" AutoGenerateColumns="false" DataKeyNames="id"
                    RowStyle-CssClass="gridviewitem" FooterStyle-CssClass="gridviewitem" CssClass="gridview" 
                      AlternatingRowStyle-CssClass="gridview_alternate" ShowFooter="true" 
                      onrowdatabound="GridDisplay_RowDataBound"   >
                    <Columns>
                        <asp:TemplateField ItemStyle-HorizontalAlign="Center"  HeaderText="S.no">
                            <ItemTemplate> <%#Container.DataItemIndex+1 %></ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:BoundField HeaderText="Item Name" DataField="ItemName" />
                        <asp:BoundField HeaderText="UOM" DataField="UOMName" />
                        <asp:BoundField HeaderText="Ordered Qty" DataField="Quantity" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:0.00}"  />
                        
                        <asp:TemplateField HeaderText ="Total Received Qty"  ItemStyle-HorizontalAlign="Right">
                            <ItemTemplate>
                                <asp:Label ID="TxtTotalQuantity" Width="80px" runat="server" onKeyPress="return isNumberKey(this.id,event)" Text="0"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText ="Pending Qty" ItemStyle-HorizontalAlign="Right">
                            <ItemTemplate>
                                <asp:Label ID="LblPendingQuantity" Width="80px" onKeyPress="return isNumberKey(this.id,event)" runat="server"  Text="0"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="Received Qty" ItemStyle-HorizontalAlign="Right" >
                            <ItemTemplate>
                               <asp:TextBox ID="TxtReceivedQuantity"  Width="80px" onKeyPress="return isNumberKey(this.id,event)" onblur="calcTotal()" CssClass="inputnumber"  runat="server" Text="0"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="Rate" ItemStyle-HorizontalAlign="Right"  >
                            <ItemTemplate>
                                <asp:TextBox ID="TxtRate" runat="server" Width="80px" onKeyPress="return isNumberKey(this.id,event)" onblur="calcTotal()" CssClass="inputnumber" Text="0"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="Amt" ItemStyle-HorizontalAlign="Right"  >
                            <ItemTemplate>
                                <asp:TextBox ID="TxtAmount" runat="server" Width="80px" Enabled="false" onKeyPress="return isNumberKey(this.id,event)" CssClass="inputnumber" Text="0"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                         <asp:TemplateField HeaderText="Discount" ItemStyle-HorizontalAlign="Center" >
                            <ItemTemplate>
                                <asp:TextBox ID="TxtDiscount"  runat="server" Width="80px" onKeyPress="return isNumberKey(this.id,event)" onblur="calcTotal()" CssClass="inputnumber" Text="0"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="Total Amount" ItemStyle-HorizontalAlign="Center" >
                            <ItemTemplate>
                                <asp:TextBox ID="TxtTotalAmount" Width="80px"  Enabled="false" runat="server" onKeyPress="return isNumberKey(this.id,event)"   CssClass="inputnumber" Text="0"></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
               
            
              <script language="javascript" type="text/javascript">
               function calcTotal()
                {
                    var grid=document.getElementById('<%=this.GridDisplay.ClientID %>');
                    var row_count=eval(document.getElementById("HidGrdRowCount").value);
                    var Gtotal=0;
                    
                    for(var i=1; i<=row_count; i++)
                    {
                                               
                    
                       var grdrow=grid.rows[i];
                       var gridCell1 = grdrow.cells[6];
                       var cell1_value = 0;
                       if (gridCell1.childNodes.item(1).value != '') {
                           cell1_value = parseFloat(gridCell1.childNodes.item(1).value);
                       }
                       
                       var gridCell2 = grdrow.cells[7];
                       var cell2_value=0;
                        if (gridCell2.childNodes.item(1).value != '')
                           {
                            cell2_value = parseFloat(gridCell2.childNodes.item(1).value);
                           }
                       var gridCell3 = grdrow.cells[8];
                       gridCell3.childNodes.item(1).value=(cell1_value*cell2_value).toFixed(2);
                       
                       var gridCell4 = grdrow.cells[9];
                       var cell4_value = 0;
                       if (gridCell4.childNodes.item(1).value != '')
                       {
                        cell4_value = parseFloat(gridCell4.childNodes.item(1).value);
                       }
                       
                       var gridCell5 = grdrow.cells[10];
                       gridCell5.childNodes.item(1).value=((cell1_value*cell2_value)-cell4_value).toFixed(2);
                       
                       Gtotal=parseFloat(Gtotal)+ parseFloat(((cell1_value*cell2_value)-cell4_value).toFixed(2));
                    }
                    var gtotalid=document.getElementById("HidGrdTotal").value;
                    document.getElementById(gtotalid).value =Gtotal.toFixed(2);
                }
            </script>
      </div>
     </div>
            </ContentTemplate>
       </asp:UpdatePanel>
       <div style="clear:both">&nbsp;</div>
       
       <table  style="margin-left:5%; margin-right:5%; width:90%; margin-top:5px;">
     
               <tr>
                    <td align="right">                    
                        <asp:Button ID="BtnSave" Text="Save" runat="server" CssClass="button" />&nbsp;  
                   </td>
                   
                   <td align="left">
                        <asp:Button ID="BtnClose" runat="server" Text="Close" CausesValidation="false" 
                               CssClass="button" onclick="BtnClose_Click" />
                    </td>
               </tr>
       </table>
       
    </div>
    </form>
</body>
</html>
